Type ProjectSelector


	Field Window : TGadget
	Field LogoPanel : TGadget
	Field Logo : TPixmap
	Field Pos : UIRect
	Field Gadgets : TGadget[]
	Field ProjWin : NewProjectWindow
	Field Tool_List : TList = New TList
	Field QuickTimer : TTimer
	Method New()
	
		
		Local Gads : TGadget[4]	
		
		QuickTimer = CreateTimer(30)
		
		Window = CreateWindow( "Spaget - Select Project..",0,0,400,400,Null,WINDOW_TITLEBAR|WINDOW_CENTER )
		LogoPanel = CreatePanel(0,0,400,210,Window)
		Logo = LoadPixmap("media/editor/logo.png")
		SetPanelPixmap(LogoPanel,Logo)
		
		Gads[0] = CreateListBox(10,230,370,100,Window)
		
		Local dir : Int = ReadDir("Projects")
		Local T : String
		Repeat
		
			T=NextFile( dir )
			If T="." Or T=".." Continue

			AddGadgetItem(Gads[0],T,0,-1,"",T)
		Until T = ""
		
		Gads[1] = CreateButton("New Project",10,340,120,20,Window)
		Gads[2] = CreateButton("Load Project",130,340,120,20,Window)
		Gads[3] = CreateButton("Cancel",260,340,120,20,Window)
		Gadgets = Gads
	
	End Method


	Method Update()
		Local EID : Int = EventID()
		Local Obj : Object = EventSource()
		
		WaitEvent()
		If ProjWin <> Null Then
			ProjWin.Update(EID,Obj)
		EndIf		
		Select EID
		
			Case EVENT_WINDOWCLOSE
				If Obj = Window Then End	
			
			Case EVENT_GADGETACTION
				Select Obj
				
					Case Gadgets[1]
						ProjWin = New NewProjectWindow
						ProjWin.SetAll("New Project",0,0,400,200,Tool_List)
						ProjWin.Set()
					Case Gadgets[3]
						End
				
					Case Gadgets[2]
						If SelectedGadgetItem(Gadgets[0]) <> -1 Then
							
							CurrentProject = GadgetItemText(Gadgets[0],SelectedGadgetItem(Gadgets[0]))
							If MainEd <> Null Then
								If MainEd.MainWindow <> Null Then
									FreeGadget MainEd.MainWindow	
								EndIf
							EndIf
							Config.SaveConfig()
							AppTitle = "Spaget - "+CurrentProject
							If Proj <> Null Then
							
								FreeGadget Proj.Window
								Proj = Null
							
							EndIf
							MainEd = New Editor_Main
							MainEd.Init()
							FreeGadget Window
							Proj = Null							
							
						Else
							Notify "Please Select a Project"
						EndIf
				
				
				End Select	
		
		End Select

	End Method

End Type
